package com.boolib.scheck.util;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

@Slf4j
public class PropertiesUtil {

     private  static Properties properties;



    //java classloader 加载后就加载static中的内容
    static {

        String fileName = "scheck.properties";

        properties = new Properties();
        try {
            properties.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName),"utf-8"));


        } catch (IOException e) {
            log.info("配置文件读取异常");
        }


    }


    public static String getProperty(String key){
        String  value = properties.getProperty(key.trim());

        if(StringUtils.isBlank(value)) {
            return null;
        }
        return  value.trim();
    }


    public static String getProperty(String key,String defaultValue){
        String  value = properties.getProperty(key.trim());

        if(StringUtils.isBlank(value)) {
            value = defaultValue;
        }
        return  value.trim();
    }


}
